<?php
class FilterAction extends Action {
	public function username() {
		$q = $_REQUEST["key"];
	
		$Dao = M("User");

		$items = $Dao -> getField("uid,nickname");

		$result = array();
		foreach ($items as $id => $key) {
			if($q)
			{
			if (strpos(strtolower($key), $q) !== false) {
				array_push($result, array("id" => $id, "text" => $key));
			}
			}
			else array_push($result, array("id" => $id, "text" => $key));
			if (count($result) > 11)
				break;
		}
		echo json_encode($result);
	}
	public function pname() {
		$q = $_REQUEST["key"];
		
		$Dao = M("Project");

		$items = $Dao -> getField("pid,pname");

		$result = array();
		foreach ($items as $id => $key) {
			if($q)
			{
				if (strpos(strtolower($key), $q) !== false) {
				array_push($result, array("id" => $id, "text" => $key));
			}
			}
			else array_push($result, array("id" => $id, "text" => $key));
			if (count($result) > 11)
				break;
		}
		echo json_encode($result);
	}
	public function fund() {
		$q = $_REQUEST["key"];
		
		$Dao = M("Fund");

		$items = $Dao -> getField("funid,fund");

		$result = array();
		foreach ($items as $id => $key) {
			if($q)
			{
				if (strpos(strtolower($key), $q) !== false) {
				array_push($result, array("id" => $id, "text" => $key));
			}
			}
			else array_push($result, array("id" => $id, "text" => $key));
			if (count($result) > 11)
				break;
		}
		echo json_encode($result);
	}
	public function industry() {
		$q = $_REQUEST["key"];
		
		$Dao = M("Industry");

		$items = $Dao -> getField("indid,industry");

		$result = array();
		foreach ($items as $id => $key) {
			if($q)
			{
				if (strpos(strtolower($key), $q) !== false) {
				array_push($result, array("id" => $id, "text" => $key));
			}
			}
			else array_push($result, array("id" => $id, "text" => $key));
			if (count($result) > 11)
				break;
		}
		echo json_encode($result);
	}
	

}
?>